package net.prasenjit.poc.integration;

import net.prasenjit.poc.integration.model.BookOrder;
import net.prasenjit.poc.integration.model.OnlineBookOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.Transformer;

/**
 * Created by PPurohit on 12/26/2014.
 */
@MessageEndpoint
public class DeliveryTransformer {

    final Logger logger = LoggerFactory.getLogger(DeliveryTransformer.class);

    /**
     * Transforms a <code>BookOrder</code> that is a delivery
     * into a <code>OnlineBookOrder</code>.
     */
    @Transformer(inputChannel = "delivery", outputChannel = "post")
    public OnlineBookOrder processMessage(BookOrder order) {
        logger.debug("In DeliveryTransformer.  title='{}'  quantity={}  orderType={}",
                new Object[]{order.getTitle(),
                        order.getQuantity(),
                        order.getOrderType()});

        return new OnlineBookOrder(order.getTitle(), order.getQuantity(),
                order.getOrderType(),
                "1060 West Addison Chicago, IL 60613");
    }

}
